import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:ui/view/home/view.dart';
import 'package:ui/view/info/view.dart';
import 'package:ui/view/setting/view.dart';

import 'logic.dart';

class TabViewPage extends StatelessWidget {
  const TabViewPage({super.key});

  @override
  Widget build(BuildContext context) {
    final logic = Get.put(TabViewLogic());

    return Obx(() {
      return Scaffold(
        // appBar: AppBar(title: const Text("标签配置")),
        body: PageView(
          // 滑页控制器
          controller: logic.pagecon,
          // 滑动触发事件
          onPageChanged: (v) => logic.position.value = v,
          // 页面列表
          children: [HomePage(), SettingPage(), InfoPage()],
        ),
        // 底部按钮栏
        bottomNavigationBar: BottomNavigationBar(
          // 底部导航栏的底部导航栏项目具有固定宽度。
          // type: BottomNavigationBarType.fixed,
          unselectedItemColor: Colors.black,
          selectedItemColor: const Color.fromARGB(255, 102, 204, 255),

          onTap: (p) {
            if (p == 3) {
              debugPrint("退出！");
              SystemNavigator.pop();
            } else {
              logic.pagecon.jumpToPage(p);
              logic.position.value = p;
            }
          },
          currentIndex: logic.position.value,
          items: logic.iconMap.keys
              .map(
                (e) => BottomNavigationBarItem(
                  icon: Icon(logic.iconMap[e]),
                  label: e,
                ),
              )
              .toList(),
        ),
      );
    });
  }
}
